window.onload=function (){
    let head=document.getElementById('head');
    let left=document.getElementById('left');
    let right=document.getElementById('right');
    let abs=document.getElementById('abs');
    let headTip=document.getElementById('headTip');
    let ifr=document.getElementById('ifr');
    let bigPic=document.getElementById('bigPic');

    let pics=['../../imgs/pic.png','../../imgs/蛋糕图1.png','../../imgs/蛋糕图2.png'];
    let index=0;

    function changePages(name){
        let height='';
        let src='';
        switch (name){
            case "首页":{
                height='854px';
                src="view/page/indexContent/indexContent.html";
            }break
            case "品牌与产品":{
                height='870px';
                src="view/page/brandAndProducts/brandAndProducts.html";
            }break
            case  "联营合作":{
                height='650px';
                src='view/page/jointVenture/jointVenture.html';
            }break
            case "配套服务":{
                height='1200px';
                src='view/page/supportService/supportScervice.html';
            }break
            case "门店信息":{
                height='1450px';
                src="view/page/brandInfo/brandInfo.html";

            } break
            case  "关于我们":{
                src='view/page/aboutUs/aboutUs.html'
                height='850px';
            }break
        }
        ifr.style.height=height;
        ifr.src=src;
    }
    function change (ev){
        let target=ev.target;
        let name="";
        if (target.tagName.toLowerCase()==='li'){
            clearStyle();
            target.classList.add('headClick');
            name=target.firstElementChild.innerHTML;
        }else if (target.tagName.toLowerCase()==='a'){
            clearStyle();
            target.parentNode.classList.add('headClick');
            name=target.innerHTML;
        }
        if (name)
            changePages(name);
    }

    function clearStyle(){//清除样式
        let lefts=[...left.children];
        let rights=[...right.children];
        lefts.forEach(function (value, index, array){
            array[index].classList.remove('headClick');
        })
        rights.forEach(function (value, index, array){
            array[index].classList.remove('headClick');
        })
    }

    function display(){
        headTip.style.display='block';
    }
    function  lost(){
        headTip.style.display='none';
    }

    function changePic(){
        index++;
        if (index>pics.length-1)
            index=0;
        bigPic.style.opacity='0';
        setTimeout(()=>{
            bigPic.src=pics[index];
            bigPic.style.opacity='1';
        },350)
    }


    headTip.onmouseover=display;
    headTip.onmouseout=lost;
    abs.onmouseover=display;
    abs.onmouseout=lost;
    head.onclick=change;
    bigPic.onclick=changePic;


}
